package com.example.smartplay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.smartplay.entity.Apply;
import com.example.smartplay.entity.Club;
import com.example.smartplay.entity.Inform;
import com.example.smartplay.entity.Result;
import com.example.smartplay.mapper.ApplyMapper;
import com.example.smartplay.service.ApplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartplay.utils.JwtUtil;
import com.example.smartplay.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2024-07-11
 */
@Service
public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements ApplyService {
    @Autowired
    private ApplyMapper applyMapper;

    //分页 查询申请
    @Override
    public Result getApply(Integer pageNum, Integer pageSize) {
        Page<Apply> page = new Page<>(pageNum, pageSize);
        // 查询当前登录用户的 clubId（假设从 JWT 中获取）
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer clubId = (Integer) map.get("club_id");

        //查询登录用户的role信息
        String role = (String) map.get("role");

    /*    // 构造查询条件
        QueryWrapper<Apply> wrapper = new QueryWrapper<>();
        if (role.equals("ADMIN")) {
            // 管理员角色，不添加任何额外条件，可以查看所有社团的申请信息

        } else {
            // 具有社长身份，只查询本社团
            wrapper.eq("club_id", clubId);
        }
            return Result.success(applyMapper.selectPage(page, wrapper));
*/
        return Result.success(applyMapper.selectPage(page, null));
        }

}

